<script type="text/javascript">
$(function(){
	var pg = App.soagov.svcIndex.ui,
		gd = pg.find('.grid');

	gd.mac('grid', {
		cols : [{
			field : 'id', title : '<input type="checkbox" name="all" />', width : 24,
			render : function(r, tr, gd) {
				return '<input type="checkbox" name="code" value="' + r.code + '"/>';
			}
		}, {
			field : 'code', title : '编号', width : 140,
			render: function(r){
				return $('<span class="a"></span>').click(function(){
					App.open({
						ctx: 'soagov',
						action: 'svcEdit',
						title: '编辑服务',
						params: r
					}, gd.load);
				}).append(r.code);
			}
		}, {
			field: 'name', title : '名称', width: 140
		},{
			field: 'ver', title : '编辑流程', width: 80,
			render: function(r){
				var f = $('<form method="post" action="/soagov/flow/edit.do" target="_blank"></form>');
				f.append('<input type="hidden" name="id" value="' + r.id + '" />');
				f.append('<input type="hidden" name="code" value="' + r.code + '" />');
				f.append('<input type="hidden" name="name" value="' + r.name + '" />');
				f.append('<input type="hidden" name="type" value="1" />');
				f.append('<input type="hidden" name="catalog" value="svc" />');
// 				f.append('<input type="hidden" name="appId" value="'+ svcAppId +'" />');
				f.append('<input type="hidden" name="url" value="/soagov/#flow/edit?catalog=svc&id='
					+ r.id + '&code=' + r.code + '" />');
				f.append($('<span class="a">编辑流程</span>').click(function(){
					f[0].submit();
				}));
				return f;
			}
		},{
			field: 'memo', title : '备注', width: 200
		},{
			field: 'opt', title : '操作', width: 40,
			render: function(r) {
				return $('<span class="a"></span>').click(function(){
					mac.confirm('确定要 删除 ' + r.code + ' 服务吗？', function(){
						$.post(App.ctx + '/svc/delete.do', {
							key: r.id,
						}, function(rs){
							var ro = mac.eval(rs);
							if (ro.success) {
								gd.load();
							} else {
								mac.alert(ro.data, ro.params);
							}
						});
					});
				}).append('删除');
			}
		}],
		loader: {
			url: App.ctx + '/svc/list.do' ,
			params: { pageNo: 1, pageSize: 20 },
			autoLoad: true
		},
		pagerLength: 20
	});
	
	pg.seek('key').keydown(function(e){
		if (e.keyCode == 13) {
			gd.load({ key: $(this).val() });
		}
	});
	pg.seek('back').click(function(){
		App.show({
			ctx : 'soagov',
			action : 'home'
		}, $.noop, $('#body'));
	});
	pg.seek('add').click(function(){
		var p = pg.parent();
		App.open({
			ctx: 'soagov',
			action: 'svcEdit',
			title: '添加新服务'
		}, gd.load);
	});
	pg.seek('del').click(function(){
		var a = $.map(gd.find('checkbox[name=code]'), function(n){
			return n.val();
		});
		$.post(App.ctx + '/svc/delete', {
			key: r.id
		}, function(rs) {
			var ro = mac.eval(rs);
			if (ro.success) {
				gd.load();
			}
		});
	});

	function adjust(){
		var h = pg.parent().height();
		pg.height(h - 30);
		gd.parent().height(h - 80);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust(); 
});
</script>
<div class="navi">
	<span class="a" name="back">流程设计</span>&gt;&gt;
	<span name="title">服务管理</span>
</div>
<div class="head">
	<button name="add">添加</button>
	<button name="del">删除</button>
	<span class="fr">关键字查找：<input type="text" name="key" /></span>
</div>
<div class="body">
	<div class="grid" name="grid"></div>
</div>